//
//  XLAllApplyHeaderView.m
//  industry
//
//  Created by xl on 2020/11/30.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLAllApplyHeaderView.h"

@interface XLAllApplyHeaderView ()

@property (nonatomic, strong) XLView *lineView;
@property (nonatomic, strong) XLLabel *titleLB;
@property (nonatomic, strong) XLButton *editBtn;

@end
@implementation XLAllApplyHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteBgColor];
        
        [self addSubview:self.lineView];
        [self addSubview:self.titleLB];
        [self addSubview:self.editBtn];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(30);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(3, 14));
        }];
        
        [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lineView.mas_right).offset(10);
            make.centerY.equalTo(self);
        }];
        
        [_titleLB sizeToFit];
        
        [_editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-30);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(16, 16));
        }];
    }
    return self;
}

#pragma mark - Public
- (void)loadHeaderViewTitle:(NSString *)title showEdit:(BOOL)showEdit{
    _titleLB.text = title;
    _editBtn.hidden = !showEdit;
}

#pragma mark - UIButton
- (void)clickEdit {
    if (self.editBlock) {
        self.editBlock();
    }
}

#pragma mark - setter/getter
- (XLView *)lineView {
    if (!_lineView) {
        _lineView = [XLView new];
        _lineView.backgroundColor = [UIColor blueBgColor];
        _lineView.layer.cornerRadius = 1.5;
        _lineView.layer.masksToBounds = YES;
    }
    return _lineView;
}

- (XLLabel *)titleLB {
    if (!_titleLB) {
        _titleLB = [XLLabel new];
        _titleLB.font = [UIFont fontOfPingFangSCRegularWithSize:15];
        _titleLB.textColor = [UIColor blackFontColor];
    }
    return _titleLB;
}

- (XLButton *)editBtn {
    if (!_editBtn) {
        _editBtn = [XLButton new];
        [_editBtn setCurrentButtonHotSize:CGSizeMake(40, 40)];
        [_editBtn setImage:XLIMAGE(@"bj") forState:UIControlStateNormal];
        [_editBtn addTarget:self action:@selector(clickEdit) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editBtn;
}
@end
